<div class="filter">
    <div class="f0 item" style="width: 120px;">
        <select data-am-selected>
            <option value="-1" checked>全部游戏</option>
        </select>
    </div>

    <div class="f1 item" style="width: 100px;">
        <input type="text" class="am-form-field" placeholder="起始日期" id="start"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    <div class="f2 item" style="width: 100px;">
        <input type="text" class="am-form-field" placeholder="结束日期" id="end"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    <div class="f3 item" style="width: 110px;">
        <input type="text" class="am-form-field" placeholder="投注IP" />
    </div>
    
    <div class="f10 item">
        <select>
            <option value="uid">用户名</option>
            <option value="id">订单号</option>
        </select>
    </div>
    <div class="f7 item" style="width: 110px;">
        <input type="text" class="am-form-field" placeholder="" />
    </div>

    <div class="f4 item">
        <select data-am-selected>
            <option value="-1" selected>所有状态</option>
            <option value="0">未结算</option>
            <option value="1">已结算</option>
            <option value="2">撤单</option>
            <option value="3">重开奖</option>
        </select>
    </div>
    <div class="f8 item">
        <select data-am-selected>
            <option value="-1" selected>中奖状态</option>
            <option value="1">中奖</option>
            <option value="2">没中奖</option>
        </select>
    </div>

    <div class="f5 item" style="width: 100px;">
        <input type="text" class="am-form-field" placeholder="起始期数" />
    </div>
    <div class="f6 item" style="width: 100px;">
        <input type="text" class="am-form-field" placeholder="结束期数" />
    </div>
    <div class="button item">
        <button type="button" class="am-btn am-btn-primary">查看</button>
    </div>
</div>

<table class="am-table am-table-bordered am-table-striped am-table-compact" id="result-table">
  <thead>
  <tr>
    <th style="width:240px;">单号</th>
    <th>用户</th>
    <th>彩种/期数</th>
    <th>明细</th>
    <th width="140px">IP</th>
    <th>投注</th>
    <th>返水</th>
    <th>结果</th>
    <th>赔率差</th>
    <th>返水差</th>
    <th width="110px">投注时间</th>
    <th width="110px">结算时间</th>
    <th width="40px">来源</th>
  </tr>
  </thead>
  <tbody>
  </tbody>
</table>
<div class="zxf_pagediv"></div>

<script>
    if (context.center.betOper == 'seeOne' && context.center.user) {
        context.center.betOper = undefined;
        $(".f7 input").val(context.center.user.mobile);
    }
    Util.fillGames($(".f0 select"));
    $(".f1 input").datepicker({format: 'yyyy-mm-dd'});
    $(".f2 input").datepicker({format: 'yyyy-mm-dd'});
    $(".f1 input").datepicker("setValue", new Date().Format("yyyy-MM-dd"));
    $(".f2 input").datepicker("setValue", new Date().Format("yyyy-MM-dd"));
    Util.restorePageFilter();

    var _f = Util.queryTemplate($("#result-table tbody"), ".zxf_pagediv", $(".button button"), function(page, size, cb) {
        var data = {
            pageNum: page,
            pageSize: size,
        };
        var type = $(".f0 select").val();
        if (type == -1) type = null;
        var v = $(".f3 input").val().trim();
        if (v) data.ip = v;
        if ($(".f10 select").val() == 'uid') {
            var v = $(".f7 input").val().trim();
            if (v) data.uid = v;
        }
        else if ($(".f10 select").val() == 'id') {
            var v = $(".f7 input").val().trim();
            if (v) data.id = v;
        }
        var v = $(".f4 select").val();
        if (v != -1) data.state = v;
        var v = $(".f5 input").val().trim();
        if (v) data.startIssue = v;
        var v = $(".f6 input").val().trim();
        if (v) data.endIssue = v;
        var v = $(".f1 input").val();
        if (v) data.start = v;
        var v = $(".f2 input").val();
        if (v) data.end = v;
        if (data.startIssue && data.endIssue) data.issues = data.startIssue + "," + data.endIssue;
        else if (data.startIssue) data.issues = data.startIssue + ",";
        else if (data.endIssue) data.issues = "," + data.endIssue;

        var v = $(".f8 select").val();
        data.win = v;

        if (data.end && data.start && 
            new Date(data.end).getTime() - new Date(data.start).getTime() > 7 * 24 * 3600 * 1000) {
            alert2("查询的时间跨度，不能超过7天", true);
            return;
        }

        Util.savePageFilter([".f0 select", ".f1 input", ".f2 input", ".f3 input", ".f7 input", ".f8 select", ".f4 select", ".f5 input", ".f6 input"]);
        startLoading();
        CMD.query_bet(type, "", data, function(r) {
            stopLoading();
            cb(r);
        });
    }, function(table, list, sum) {
        if (Util.isEmpty(list)) {
            table.append("<tr><td colspan='13'>暂无数据</tr>");
            return;
        }

        var tr = $("<tr></tr>");
        tr.append("<td colspan='5'>合计</td>");
        tr.append("<td>" + (sum.amount/100).toFixed(2) + "</td>");
        tr.append("<td>" + (sum.back/100).toFixed(2) + "</td");
        tr.append("<td>" + (sum.profit/100).toFixed(2) + "</td>");
        tr.append("<td>" + (sum.rprofit/100).toFixed(2) + "</td>");
        tr.append("<td>" + (sum.rback/100).toFixed(2) + "</td>");
        tr.append("<td colspan='3'></td>");
        table.append(tr);

        for (var i in list) {
            var o = list[i];
            var tr = $("<tr></tr>");            
            tr.append("<td>" + (o.id) + "</td>");
            tr.append("<td>" + (o.user.mobile || "游客") + "</td>");
            var target = Util.convertTarget(o.type, o.target);
            tr.append("<td>" + get_game_display_name(o.type) + " 第" + o.issue + "期</td>");
            tr.append("<td>" + target + "@" + o.rate + "</td>");
            tr.append("<td class='ip'>" + o.ip + "</td>");
            tr.append("<td>" + (o.amount/100) + "</td>");
            tr.append("<td>" + ((o.back || 0)/100) + "</td>");

            if (o.state == 0) {
                tr.append("<td>未开奖</td>");
            }
            else {
                if (o.profit > 0)
                    tr.append("<td class='red'>" + (o.profit/100).toFixed(3) + "</td>");
                else
                    tr.append("<td class='green'>" + (o.profit/100).toFixed(3) + "</td>");
            }
                
            tr.append("<td>" + ((o.rprofit || 0)/100) + "</td>");
            tr.append("<td>" + ((o.rback || 0)/100) + "</td>");
            
            tr.append("<td>" + Util.converServerTime(o.time).substring(5) + "</td>");
            if (o.complete)
                tr.append("<td>" + Util.converServerTime(o.complete).substring(5) + "</td>");
            else
                tr.append("<td></td>");
            tr.append("<td>" + (o.source || '') + '</td>');
            table.append(tr);
        }
    });
</script>
   